package com.bysc.baseservice.handler;

import com.bysc.commonutils.Results;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */

@ControllerAdvice

public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)

    @ResponseBody

    public Results error(Exception e) {
        e.printStackTrace();
        return Results.error();
    }
    @ExceptionHandler(ArithmeticException.class) @ResponseBody
    public Results error(ArithmeticException e){
        e.printStackTrace();
        return Results.error().message("特殊异常处理");
    }
    @ExceptionHandler(BaiYunException.class) @ResponseBody
    public Results error(BaiYunException e){
        e.printStackTrace();
        return Results.error().message(e.getMsg()).code(e.getCode());

    }

}
